<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
    <head>
    <meta charset="UTF-8">
    <%@ include file="/WEB-INF/views/include/head.jsp"%> 
    <%@include file="/WEB-INF/views/include/treeview.jsp" %>
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
        <script type="text/javascript">
            var setting;
            var zNodes;
            var tree;
            //初始化
            $(document).ready(function(){
                
                 setting = {check:{enable:true,nocheckInherit:true},view:{selectedMulti:false},
                            data:{simpleData:{enable:true}},callback:{beforeClick:function(id, node){
                                tree.checkNode(node, !node.checked, true, true);
                                return false;
                            }}};
                // 用户-菜单
                 zNodes=[
                        <c:forEach items="${menuList}" var="menu">{id:"${menu.id}", pId:"${not empty menu.parent.id?menu.parent.id:0}", name:"${not empty menu.parent.id?menu.menuName:'权限列表'}"},
                        </c:forEach>];
                // 初始化树结构
                 tree = $.fn.zTree.init($("#menuTree"), setting, zNodes);
                // 不选择父节点
                tree.setting.check.chkboxType = { "Y" : "ps", "N" : "s" };
                // 默认选择节点
                var ids = "${role.menuIds}".split(",");
                for(var i=0; i<ids.length; i++) {
                    var node = tree.getNodeByParam("id", ids[i]);
                    try{tree.checkNode(node, true, false);}catch(e){}
                }
               
                var  nodes = tree.getNodes();
                var nodes_array = tree.transformToArray (nodes);
                for (var i=0, l=nodes_array.length; i<l; i++) {
                     tree.setChkDisabled(nodes_array[i], true);     
                }
                // 默认展开全部节点
                tree.expandAll(true);
               });
            
            //删除方法
            function delRole(){
                // 调用后台删除方法
                $.post("${ctx}/database/role/delete?id=${role.id}",'',function(result){
                    // 提示信息
                    tipParent(result.message);
                    // 返回状态
                    if(result.statusCode==STATUSCODEOK){
                        // 刷新页面
                        window.parent.frames[0].location.reload();
                        // 关闭页面
                        closeWin(); 
                     }
                },'json');
           }
        </script>
    </head>
    <body>
        <!--头部-->
        <div class="layerHeader clearfix">
            <!-- 查看 -->
            <p class="headerTitle"><spring:message code="role_show"/></p>
            
                <shiro:hasPermission name="database:role:edit">
                    <!-- 编辑 -->
                    <div class="headerButton clearfix" >
                        <button type="button" onclick="popup('1000px','650px','${ctx}/database/role/form?id=${role.id}');closeWin()"><spring:message code="role_edit"/></button>
                    
                    <!-- 删除 -->
                
                    <button type="button" onclick="del(delRole)"><spring:message code="role_delete"/></button>
               
                </shiro:hasPermission>
                <!-- 关闭 -->
                
                    <button type="button" onclick="closeWin()"><spring:message code="role_cancle"/></button>
                </div>
           
        </div>
        <div class="tabBoxSm">
            <div class="tabSm smOrderBox clearfix">
                <div class="col-50 items clearfix">
                    <!-- 角色名称 -->
                    <p class="tit"><spring:message code="role_name_show"/></p>
                    <p class="tit">${role.roleName}</p>
                </div>
                <div class="col-50 items right clearfix">
                <!-- 系统数据 -->
                    <p class="tit"><spring:message code="role_sysData_show"/></p>
                    <p class="tit">
                        <c:choose>
                            <c:when test="${role.roleSys eq 0}"><spring:message code="role_no"/></c:when>
                            <c:when test="${role.roleSys eq 1}"><spring:message code="role_yes"/></c:when>
                        </c:choose>
                    </p>
                </div>
            </div>
            <div class="tabSm smOrderBox clearfix">
                <div class="col-50 items clearfix">
                    <!-- 数据范围 -->
                    <p class="tit"><spring:message code="role_dataField_show"/></p>
                    <p class="tit" style="width: 150px">
                           <c:choose>
                            <c:when test="${role.roleScope eq 1}"><spring:message code="role_dataField1"/></c:when>
                            <c:when test="${role.roleScope eq 2}"><spring:message code="role_dataField2"/></c:when>
                            <c:when test="${role.roleScope eq 3}"><spring:message code="role_dataField3"/></c:when>
                            <c:when test="${role.roleScope eq 4}"><spring:message code="role_dataField4"/></c:when>
                            <c:when test="${role.roleScope eq 5}"><spring:message code="role_dataField5"/></c:when>
                            <c:when test="${role.roleScope eq 6}"><spring:message code="role_dataField6"/></c:when>
                        </c:choose>
                    </p>
                </div>
                <div class="col-50 right items clearfix">
                    <!-- 角色类型 -->
                    <p class="tit"><spring:message code="role_type_show"/></p>
                    <p class="tit">
                        <c:choose>
                            <c:when test="${role.roleType eq 1}"><spring:message code="role_type1"/></c:when>
                            <c:when test="${role.roleType eq 2}"><spring:message code="role_type2"/></c:when>
                            <c:when test="${role.roleType eq 3}"><spring:message code="role_type3"/></c:when>
                        </c:choose>
                    </p>
                </div>
            </div>
            <div class="tabSm smOrderBox clearfix" style="height: 400px">
                <div class="col-50 items clearfix" style="float: left;">
                    <!-- 角色授权 -->
                    <p class="tit"><spring:message code="role_accredit_show"/></p>
                    <!-- <p class="rtname fl">????</p> -->
                    <div id="menuTree" class="ztree" style="margin-top:3px;float:left;overflow: auto;height: 370px;width: 300px""></div>
                    <input  type="hidden" id="menuIds" name="menuIds" value="${role.menuIds}" >
                </div>
                <div class="col-50 right items clearfix">
                    <!-- 描述 -->
                    <p class="tit"><spring:message code="role_description_show"/></p>
                    <p class="tit" data-toggle="tooltip" title="${role.roleDescription }">${role.roleDescription}</p>
                </div>
            </div>
        </div>
        <script>
            var windowH = window.innerHeight
                    ||document.documentElement.clientHeight
                    ||document.body.clientHeight
            $('.middle').css('height',windowH - 50);
        </script>
    </body>
</html>